{extend name="public/base"/}

{block name="title"}编辑权限目录{/block}
{block name="main"}

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form action="#" method="post" class="row" id="add-form" name="add-form">
                    <div class="form-group col-md-12">
                        <label for="name">目录名称</label>
                        <input type="hidden" id="id" value="{$list.id}">
                        <input type="text" class="form-control" id="name" name="name" value="{$list.name}" placeholder="请输入目录名称" data-validate="required:请输入目录名称"/>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="icon">FA图标</label>
                        <input type="text" class="form-control" id="icon" name="icon" value="{$list.icon}" placeholder="请输入FA图标" data-validate="required:请输入FA图标"/>
                    </div>
                    <div class="form-group col-md-12">
                        <label for="sort_num">排序码</label>
                        <input type="text" class="form-control" id="sort_num" name="sort_num" value="{$list.sort_num}" placeholder="数字越大越靠前" data-validate="required:请输入排序码"/>
                    </div>
                    <div class="form-group col-md-12">
                        <button type="button" id="btn" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
                        <button type="button" class="btn btn-default" onclick="location.href='/admin/permission_category/index';return false;">返 回</button>
                    </div>
                    <!--</form>-->
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
    $(function () {
        $('#btn').click(function () {
            let name = $('#name').val();
            let icon = $('#icon').val();
            let sort_num = $('#sort_num').val();
            let id = $('#id').val();
            if (!name) {
                swal('请输入目录名称', '', 'warning');
                return false;
            }
            $.post('/admin/permission_category/edit',
                {id:id,name: name, icon: icon, sort_num: sort_num},
                function (res) {
                    console.log(res);
                    if (res.code === 1) {
                        swal(res.msg, '', 'success')
                            .then(() => {
                                location.reload();
                            });
                    } else {
                        swal(res.msg, '', 'error');
                    }
                }
            );

        });
    });
</script>
{/block}